package com.ruoyi.web.controller.xsp;

import java.util.List;

import com.ruoyi.xsp.domain.XspComment;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xsp.domain.XspCommentReply;
import com.ruoyi.xsp.service.IXspCommentReplyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回复Controller
 * 
 * @author zhiminhu
 * @date 2021-03-01
 */
@Controller
@RequestMapping("/xsp/reply")
public class XspCommentReplyController extends BaseController
{
    private String prefix = "xsp/reply";

    @Autowired
    private IXspCommentReplyService xspCommentReplyService;

    @RequiresPermissions("xsp:reply:view")
    @GetMapping()
    public String reply()
    {
        return prefix + "/reply";
    }

    /**
     * 查询回复列表
     */
    @RequiresPermissions("xsp:reply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(XspCommentReply xspCommentReply)
    {
        startPage();
        List<XspCommentReply> list = xspCommentReplyService.selectXspCommentReplyList(xspCommentReply);
        return getDataTable(list);
    }

    /**
     * 导出回复列表
     */
    @RequiresPermissions("xsp:reply:export")
    @Log(title = "回复", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XspCommentReply xspCommentReply)
    {
        List<XspCommentReply> list = xspCommentReplyService.selectXspCommentReplyList(xspCommentReply);
        ExcelUtil<XspCommentReply> util = new ExcelUtil<XspCommentReply>(XspCommentReply.class);
        return util.exportExcel(list, "reply");
    }

    /**
     * 新增回复
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存回复
     */
    @RequiresPermissions("xsp:reply:add")
    @Log(title = "回复", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(XspCommentReply xspCommentReply)
    {
        return toAjax(xspCommentReplyService.insertXspCommentReply(xspCommentReply));
    }

    /**
     * 修改回复
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        XspCommentReply xspCommentReply = xspCommentReplyService.selectXspCommentReplyById(id);
        mmap.put("xspCommentReply", xspCommentReply);
        return prefix + "/edit";
    }

    /**
     * 修改保存回复
     */
    @RequiresPermissions("xsp:reply:edit")
    @Log(title = "回复", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(XspCommentReply xspCommentReply)
    {
        return toAjax(xspCommentReplyService.updateXspCommentReply(xspCommentReply));
    }

    /**
     * 删除回复
     */
    @RequiresPermissions("xsp:reply:remove")
    @Log(title = "回复", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(xspCommentReplyService.deleteXspCommentReplyByIds(ids));
    }

    /**
     * 审核评论
     */
    @GetMapping("/check/{id}")
    public String check(@PathVariable("id") Integer id, ModelMap mmap)
    {
        XspCommentReply xspCommentReply = xspCommentReplyService.selectXspCommentReplyById(id);
        mmap.put("xspCommentReply", xspCommentReply);
        return prefix + "/check";
    }
    /**
     * 批量审核
     */
    @RequiresPermissions("xsp:reply:update")
    @Log(title = "批量审核", businessType = BusinessType.CHECK)
    @PostMapping( "/checkAll")
    @ResponseBody
    public AjaxResult checkAll(String ids,int status)
    {

        return toAjax(xspCommentReplyService.checkXspCommentReplyByIds(ids,status));
    }
}
